package com.my.listeners;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class ContextSessionRequestListener implements ServletRequestListener, HttpSessionListener, ServletContextListener {

    //application(ServletContext)
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("监听ServletContext，创建ServletContext对象：" + servletContextEvent);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("监听ServletContext，销毁ServletContext对象：" + servletContextEvent);
    }

    //Request
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        System.out.println("监听Request，销毁ServletRequest对象：" + servletRequestEvent);
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        System.out.println("监听Request，创建ServletRequest对象：" + servletRequestEvent);
    }

    //Session
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println("监听Session，创建HttpSession对象：" + httpSessionEvent);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        System.out.println("监听Session，销毁HttpSession对象：" + httpSessionEvent);
    }
}
